<?php
require("header.php");
require("left.php");
?>
<?php
require("admin/conn.php");
if(isset($_GET['page']))     //由GET方法获得页面传入当前页数的参数
{
    $page = $_GET['page'];
}
else
{
    $page = 1;
}
$page_size = 5;              //每页显示5条数据

//获取数据总量
$sql = 'select * from artcontent ';
$result = mysql_query($sql);
$total = mysql_num_rows($result);

//开始计算总页数
if($total)
{
    //如果总数据量小于$page_size，那么只有一页
    if($total < $page_size)
        $page_count = 1;
    //如果有余数，则总页数等于总记录数除以页数的结果取整再加1
    if($total % $page_size)
    {
        $page_count = (int)($total/$page_size) + 1;
    }
    //如果没有余数，则页数等于总数据量除以每页数的结果
    else
    {
        $page_count = $total/$page_size;
    }
}
else
{
    $page_count = 0;
}
//翻页链接

$turn_page = '';
if($page == 1)
{
    $turn_page .= '首页 | 上一页 |';
}
else
{
    $turn_page .= '<a href=index.php?page=1> 首页</a> | <a href=index.php?page='.($page-1).'> 上一页 </a> |';
}
if($page == $page_count || $page_count == 0)
{
    $turn_page .= ' 下一页 | 尾页';
}
else
{
    $turn_page .= '<a href=index.php?page='.($page+1).'> 下一页 </a>|<a href=index.php?page='.$page_count.'> 尾页 </a>';
}

$sql = 'SELECT * FROM artcontent ORDER BY PostData DESC limit '. ($page-1)*$page_size .', '.$page_size;
$result = mysql_query($sql) OR die("<br/>ERROR: <b>".mysql_error()."</b><br/>产生问题的SQL：".$sql);
?>
		<div id="main">
			<div class="artical">
<?php
if($num = mysql_num_rows($result))
{
    while($row = mysql_fetch_array($result,MYSQL_ASSOC))
    {
        if($row['ding']==1)
        {
?>
			         <h4><span type="text/css" style="color:#89bd3b">[顶]</span>&nbsp;&nbsp;<?php echo"<a href=artview.php?Art_id=". $row['Art_id'] .">".$row['Title']."</a>"; ?></h4>
					 <p class="time"><?php  echo $row['PostData']; ?></p>
					 <p class="content">
                     <?php if(mb_strlen($row['Content'])>=300)
                            echo mb_substr($row['Content'],0,300)."...";
                            else echo $row['Content'];
                     ?></p>
                     <p class="lable">评论（<?php echo $row['rnum'];?>）点击数（<?php echo $row['vnum'];?>）</p>					 
				     <p class="show"><?php echo" <a href=artview.php?Art_id=". $row['Art_id'] .">read more<< </a>"; ?></p>
<?php
}
else
break;
}}
?>		    
            </div>
			<div class="artical">
<?php
if($num = mysql_num_rows($result))
{
    while($row = mysql_fetch_array($result,MYSQL_ASSOC))
    {
?>
			         <h4><?php echo"<a href=artview.php?Art_id=". $row['Art_id'] .">".$row['Title']."</a>"; ?></h4>
					 <p class="time"><?php  echo $row['PostData']; ?></p>
					 <p class="content">
                     <?php if(mb_strlen($row['Content'])>=300)
                            echo mb_substr($row['Content'],0,300)."...";
                            else echo $row['Content'];
                     ?></p>
                     <p class="lable">评论（<?php echo $row['rnum'];?>）点击数（<?php echo $row['vnum'];?>）</p>					 
				     <p class="show"><?php echo" <a href=artview.php?Art_id=". $row['Art_id'] .">read more<< </a>"; ?></p>
<?php
}}
?>		    
            </div>
				
            <div class="artical">
			<p class="next"><?php echo $turn_page.'<br/><br/>';?></p>
            </div>
		</div>

</div>
<?php
require("footer.php");
?>